#include <stdio.h>
#include <fcntl.h>
int main(int argc, char *argv[])
{
	char buf[10];
	int flag = 1,i=0;
    printf("打开文件p1.png\n");
    int fd1 = open("./src/p1.jpg",O_RDONLY);
    if(fd1 == -1){
		perror("打开失败"); 
    	return;
	}
    printf("创建文件p2.png\n");
    int fd2 = creat("./src/p2.jpg",777);
    if(fd2 == -1){
		perror("创建失败"); 
    	return;
	}
		printf("加密文件\n"); 
	int ret1,ret2;
	while(flag) {
		ret1 = read(fd1,buf,sizeof(buf));
		if(ret1 == -1){
			perror("读取失败"); 
    		return;
		}
		flag = ret1; 
		if(flag== 0){
			printf("读取完成\n"); 
			break;
		}
		for(i = 0 ; i < 10 ; i++)
		{
			buf[i]++;	
		} 
		ret2 = write(fd2,buf,ret1);
		if(ret2 == -1){
			perror("加密失败"); 
    		return;
		}
			 
	}
	close(fd1);
	close(fd2);
    return 0;
}

